home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !tex / TeXsource / commontex / c / def < prev    next >
Encoding:
Text File  |  1988-04-18  |  30.4 KB  |  1,019 lines

  1. /*
  2.  *    Copyright 1986, 1987 Pat Joseph Monardo. All rights reserved.
  3.  *    Copying of this file is granted according to the provisions 
  4.  *    specified in the file COPYING which must accompany this file.
  5.  */
  6.  
  7.  
  8. /*
  9.  *              def.c
  10.  */
  11.  
  12. #include "tex.h"
  13. #include "cmds.h"
  14. #include "heap.h"
  15. #include "io.h"
  16. #include "eq.h"
  17. #include "hash.h"
  18. #include "eqstack.h"
  19. #include "evalstack.h"
  20. #include "hash.h"
  21. #include "token.h"
  22. #include "scan.h"
  23. #include "tokenstack.h"
  24. #include "expand.h"
  25. #include "arith.h"
  26. #include "str.h"
  27. #include "box.h"
  28. #include "boxlists.h"
  29. #include "tokenlists.h"
  30. #include "file.h"
  31. #include "tfm.h"
  32. #include "dvi.h"
  33. #include "page.h"
  34. #include "print.h"
  35. #include "error.h"
  36. #include "def.h"
  37.  
  38. hword   after_token;
  39. bool    long_help_seen;
  40. val             mag_set;
  41.  
  42. #define glob    (a >= 4)
  43.  
  44. #define def(code, type, value) \
  45.         {if (glob) \
  46.                 geq_define(code, type, value); \
  47.         else eq_define(code, type, value);}
  48.  
  49. #define word_def(code, value) \
  50.         {if (glob) \
  51.                 geq_word_define(code, value); \
  52.         else eq_word_define(code, value);}
  53.  
  54. get_r_token ()
  55. {
  56. restart:
  57.         do get_token();
  58.         while (cur_tok == SPACE_TOKEN);
  59.         if (cur_cs == 0 || cur_cs > FROZEN_CONTROL_SEQUENCE) {
  60.                 print_err("Missing control sequence inserted");
  61.                 help_missing_cs();
  62.                 if (cur_cs == 0) back_input();
  63.                 cur_tok = CS_TOKEN_FLAG + FROZEN_PROTECTION;
  64.                 ins_error();
  65.                 goto restart;
  66.         }
  67. }
  68.  
  69. prefixed_command ()
  70. {
  71.         int             a;
  72.         bool    e;
  73.         fnt             f;
  74.         int             j;
  75.         int             k;
  76.         val             n;
  77.         ptr             p;
  78.         ptr             q;
  79.  
  80.         a = 0;
  81.         while (cur_cmd == PREFIX) {
  82.                 if (!odd(a / cur_chr))
  83.                         a += cur_chr;
  84.                 get_nbrx_token();
  85.                 if (cur_cmd <= MAX_NON_PREFIXED_COMMAND) {
  86.                         print_err("You can't use a prefix with `");
  87.                         print_cmd_chr(cur_cmd, cur_chr);
  88.                         print("'");
  89.                         help_prefix();
  90.                         back_error();
  91.                         return;
  92.                 }
  93.         }
  94.  
  95.         if (cur_cmd != DEF && a % 4 != 0) {
  96.                 print_err("You can't use `");
  97.                 print_esc("long");
  98.                 print("' or `");
  99.                 print_esc("outer");
  100.                 print("' with `");
  101.                 print_cmd_chr(cur_cmd, cur_chr);
  102.                 print("'");
  103.                 help_pref();
  104.                 error();
  105.         }
  106.  
  107.         if (global_defs != 0) {
  108.                 if (global_defs < 0) {
  109.                         if (glob) a -= 4;
  110.                 } else {
  111.                         if (!glob) a += 4;
  112.                 }
  113.         }
  114.  
  115.         switch (cur_cmd)
  116.         {
  117.         case SET_FONT:
  118.                 def(CUR_FONT_LOC, DATA, cur_chr);
  119.                 break;
  120.  
  121.         case DEF:
  122.                 if (odd(cur_chr) && !glob && global_defs >= 0)
  123.                         a += 4;
  124.                 e = (cur_chr >= 2);
  125.                 get_r_token();
  126.                 p = cur_cs;
  127.                 scan_toks(TRUE, e);
  128.                 def(p, CALL + (a % 4), def_ref);
  129.                 break;
  130.  
  131.         case LET:
  132.                 n = cur_chr;
  133.                 get_r_token();
  134.                 p = cur_cs;
  135.                 if (n == NORMAL) {
  136.                         do      get_token();
  137.                         while (cur_cmd == SPACER);
  138.                         if (cur_tok == OTHER_TOKEN + '=') {
  139.                                 get_token();
  140.                                 if (cur_cmd == SPACER)
  141.                                         get_token();
  142.                         }
  143.                 } else {
  144.                         get_token();
  145.                         q = cur_tok;
  146.                         get_token();
  147.                         back_input();
  148.                         cur_tok = q;
  149.                         back_input();
  150.                 }
  151.                 if (cur_cmd >= CALL)
  152.                         add_token_ref(cur_chr);
  153.                 def(p, cur_cmd, cur_chr);
  154.                 break;
  155.         
  156.         case SHORTHAND_DEF:
  157.                 n = cur_chr;
  158.                 get_r_token();
  159.                 p = cur_cs; 
  160.                 def(p, RELAX, 256);
  161.                 scan_optional_equals();
  162.                 switch ((hword) n)
  163.                 {
  164.                 case CHAR_DEF_CODE:
  165.                         scan_char_num();
  166.                         def(p, CHAR_GIVEN, (hword) cur_val);
  167.                         break;
  168.  
  169.                 case MATH_CHAR_DEF_CODE:
  170.                         scan_fifteen_bit_int();
  171.                         def(p, MATH_GIVEN, (hword) cur_val);
  172.                         break;
  173.  
  174.                 default:
  175.                         scan_eight_bit_int();
  176.                         switch ((hword) n)
  177.                         {
  178.                         case COUNT_DEF_CODE:
  179.                                 def(p, ASSIGN_INT, (hword) (COUNT_BASE + cur_val));
  180.                                 break;
  181.  
  182.                         case DIMEN_DEF_CODE:
  183.                                 def(p, ASSIGN_DIMEN, (hword) (SCALED_BASE + cur_val));
  184.                                 break;
  185.  
  186.                         case SKIP_DEF_CODE:
  187.                                 def(p, ASSIGN_GLUE, (hword) (SKIP_BASE + cur_val));
  188.                                 break;
  189.  
  190.                         case MU_SKIP_DEF_CODE:
  191.                                 def(p, ASSIGN_MU_GLUE, (hword) (MU_SKIP_BASE + cur_val));
  192.                                 break;
  193.  
  194.                         case TOKS_DEF_CODE:
  195.                                 def(p, ASSIGN_TOKS, (hword) (TOKS_BASE + cur_val));
  196.                                 break;
  197.                         }
  198.                         break;
  199.                 }
  200.                 break;
  201.  
  202.         case READ_TO_CS:
  203.                 scan_int();
  204.                 n = (int) cur_val;
  205.                 if (!scan_keyword("to")) {
  206.                         print_err("Missing `to' inserted");
  207.                         help_read_to();
  208.                         error();
  209.                 }
  210.                 get_r_token();
  211.                 p = cur_cs;
  212.                 read_toks(n, p);
  213.                 def(p, CALL, (hword) cur_val);
  214.                 break;
  215.         
  216.         case TOKS_REGISTER:
  217.         case ASSIGN_TOKS:
  218.                 q = cur_cs;
  219.                 if (cur_cmd == TOKS_REGISTER) {
  220.                         scan_eight_bit_int();
  221.                         p = TOKS_BASE + cur_val;
  222.                 } else p = cur_chr;
  223.                 scan_optional_equals();
  224.                 get_nbrx_token();
  225.                 if (cur_cmd != LEFT_BRACE) {
  226.                         if (cur_cmd == TOKS_REGISTER) {
  227.                                 scan_eight_bit_int();
  228.                                 cur_cmd = ASSIGN_TOKS;
  229.                                 cur_chr = TOKS_BASE + cur_val;
  230.                         }
  231.                         if (cur_cmd == ASSIGN_TOKS) {
  232.                                 q = equiv(cur_chr);
  233.                                 if (q == NULL) {
  234.                                         def(p, UNDEFINED_CS, NULL);
  235.                                 } else {        
  236.                                         add_token_ref(q);
  237.                                         def(p, CALL, q);
  238.                                 }
  239.                                 break;
  240.                         }
  241.                 }
  242.                 back_input();
  243.                 cur_cs = q;
  244.                 q = scan_toks(FALSE, FALSE);
  245.                 if (token_link(def_ref) == NULL) {
  246.                         def(p, UNDEFINED_CS, NULL);
  247.                         free_token(def_ref);
  248.                 } else {
  249.                         if (p == OUTPUT_ROUTINE_LOC) {
  250.                                 token_link(q) = new_token();
  251.                                 q = token_link(q);
  252.                                 token(q) = RIGHT_BRACE_TOKEN + '}';
  253.                                 q = new_token();
  254.                                 token(q) = LEFT_BRACE_TOKEN + '{';
  255.                                 token_link(q) = token_link(def_ref);
  256.                                 token_link(def_ref) = q;
  257.                         }
  258.                         def(p, CALL, def_ref);
  259.                 }
  260.                 break;
  261.  
  262.         case ASSIGN_INT:
  263.                 p = cur_chr;
  264.                 scan_optional_equals();
  265.                 scan_int();
  266.                 word_def(p, cur_val); 
  267.                 break;
  268.         
  269.         case ASSIGN_DIMEN:
  270.                 p = cur_chr;
  271.                 scan_optional_equals();
  272.                 scan_normal_dimen();
  273.                 word_def(p, cur_val); 
  274.                 break;
  275.         
  276.         case ASSIGN_GLUE:
  277.         case ASSIGN_MU_GLUE:
  278.                 p = cur_chr;
  279.                 n = cur_cmd;
  280.                 scan_optional_equals();
  281.                 if (n == ASSIGN_MU_GLUE)
  282.                         scan_glue(MU_VAL);
  283.                 else scan_glue(GLUE_VAL);
  284.                 trap_zero_glue();
  285.                 def(p, GLUE_REF, (ptr) cur_val); 
  286.                 break;
  287.         
  288.         case DEF_CODE:
  289.                 if (cur_chr == CAT_CODE_BASE)
  290.                         n = MAX_CHAR_CODE;
  291.                 else if (cur_chr == MATH_CODE_BASE)
  292.                         n = 0100000;
  293.                 else if (cur_chr == SF_CODE_BASE)
  294.                         n = 077777;
  295.                 else if (cur_chr == DEL_CODE_BASE)
  296.                         n = 077777777;
  297.                 else n = 127;
  298.                 p = cur_chr;
  299.                 scan_seven_bit_int();
  300.                 p += cur_val;
  301.                 scan_optional_equals();
  302.                 scan_int(); 
  303.                 if (cur_val < 0 && p < DEL_CODE_BASE || cur_val > n) {
  304.                         print_err("Invalid code (");
  305.                         print_val(cur_val);
  306.                         if (p < DEL_CODE_BASE)
  307.                                 print("), should be in the range 0..");
  308.                         else print("), should be at most ");
  309.                         print_val(n);
  310.                         help_code();
  311.                         error();
  312.                         cur_val = 0;
  313.                 }
  314.                 if (p < MATH_CODE_BASE) {
  315.                         def(p, DATA, (hword) cur_val);
  316.                 } else if (p < DEL_CODE_BASE) {
  317.                         def(p, DATA, (hword) hi(cur_val));
  318.                 } else word_def(p, cur_val);
  319.                 break;
  320.         
  321.         case DEF_FAMILY:
  322.                 p = cur_chr;
  323.                 scan_four_bit_int();
  324.                 p += cur_val;
  325.                 scan_optional_equals();
  326.                 scan_font_ident();
  327.                 def(p, DATA, (hword) cur_val);
  328.                 break;
  329.  
  330.         case REGISTER:
  331.         case ADVANCE:
  332.         case MULTIPLY:
  333.         case DIVIDE:
  334.                 do_register_command(a);
  335.                 break;
  336.         
  337.         case SET_BOX:
  338.                 scan_eight_bit_int();
  339.                 if (glob)
  340.                         saved(0) = BOX_FLAG + 256 + cur_val;
  341.                 else saved(0) = BOX_FLAG + cur_val;
  342.                 scan_optional_equals();
  343.                 scan_box();
  344.                 break;
  345.         
  346.         case SET_AUX:
  347.                 alter_aux();
  348.                 break;
  349.  
  350.         case SET_PREV_GRAF:
  351.                 alter_prev_graf();
  352.                 break;
  353.                 
  354.         case SET_PAGE_DIMEN:
  355.                 alter_page_so_far();
  356.                 break;
  357.  
  358.         case SET_PAGE_INT:
  359.                 alter_integer();
  360.                 break;
  361.  
  362.         case SET_BOX_DIMEN:
  363.                 alter_box_dimen();
  364.                 break;
  365.  
  366.         case SET_SHAPE:
  367.                 scan_optional_equals();
  368.                 scan_int();
  369.                 n = cur_val;
  370.                 if (n <= 0)
  371.                         p = NULL;
  372.                 else {
  373.                         p = get_node(2 * n + 1);
  374.                         info(p) = n;
  375.                         for (j = 1; j <= n; incr(j)) {
  376.                                 scan_normal_dimen();
  377.                                 mem[p + 2 * j - 1].sc = cur_val;
  378.                                 scan_normal_dimen();
  379.                                 mem[p + 2 * j].sc = cur_val;
  380.                         }
  381.                 }
  382.                 def(PAR_SHAPE_LOC, SHAPE_REF, p);
  383.                 break;
  384.         
  385.         case HYPH_DATA:
  386. #ifdef  INIT
  387.                 if (cur_chr == 1) 
  388.                         new_patterns();
  389. #else
  390.                 if (cur_chr == 1) {
  391.                         print_err("Patterns can only be loaded by INITEX");
  392.                         error();
  393.                 }
  394. #endif
  395.                 else new_hyph_exceptions();
  396.                 break;
  397.         
  398.         case ASSIGN_FONT_DIMEN:
  399.                 find_font_dimen(TRUE);
  400.                 k = cur_val;
  401.                 scan_optional_equals();
  402.                 scan_normal_dimen();
  403.                 font_info[k].sc = cur_val;
  404.                 break;
  405.         
  406.         case ASSIGN_FONT_INT:
  407.                 n = cur_chr;
  408.                 scan_font_ident();
  409.                 f = cur_val;
  410.                 scan_optional_equals();
  411.                 scan_int(); 
  412.                 if (n == 0)
  413.                         hyphen_char[f] = cur_val;
  414.                 else skew_char[f] = cur_val;
  415.                 break;
  416.  
  417.         case DEF_FONT:
  418.                 new_font(a);
  419.                 break;
  420.  
  421.         case SET_INTERACTION:
  422.                 new_interaction();
  423.                 break;
  424.  
  425.         default:
  426.                 confusion("prefix");
  427.                 break;
  428.         }
  429.         if (after_token != 0) {
  430.                 cur_tok = after_token;
  431.                 back_input();
  432.                 after_token = 0;
  433.         }
  434.  
  435. trap_zero_glue ()
  436. {
  437.         if (width(cur_val) == 0 &&
  438.                 stretch(cur_val) == 0 &&
  439.                 shrink(cur_val) == 0) {
  440.                 add_glue_ref(zero_glue);
  441.                 delete_glue_ref(cur_val);
  442.                 cur_val = zero_glue;
  443.         }
  444. }
  445.  
  446. do_register_command (a)
  447.         int             a;
  448. {
  449.         ptr             l;
  450.         ptr             p;
  451.         ptr             q;
  452.         ptr             r;
  453.         ptr             s;
  454.  
  455.         q = cur_cmd;
  456.         if (q != REGISTER) {
  457.                 get_x_token();
  458.                 if (cur_cmd >= ASSIGN_INT && cur_cmd <= ASSIGN_MU_GLUE) {
  459.                         l = cur_chr;
  460.                         p = cur_cmd - ASSIGN_INT;
  461.                         goto found;
  462.                 }
  463.                 if (cur_cmd != REGISTER) {
  464.                         print_err("You can't use `");
  465.                         print_cmd_chr(cur_cmd, cur_chr);
  466.                         print("' after ");
  467.                         print_cmd_chr(q, 0);
  468.                         help_register();
  469.                         error();
  470.                         return;
  471.                 }
  472.         }
  473.         p = cur_chr;
  474.         scan_eight_bit_int();
  475.         switch (p) 
  476.         {
  477.         case INT_VAL:
  478.                 l = cur_val + COUNT_BASE;
  479.                 break;
  480.  
  481.         case DIMEN_VAL:
  482.                 l = cur_val + SCALED_BASE;
  483.                 break;
  484.                 
  485.         case GLUE_VAL:
  486.                 l = cur_val + SKIP_BASE;
  487.                 break;
  488.                 
  489.         case MU_VAL:
  490.                 l = cur_val + MU_SKIP_BASE;
  491.                 break;
  492.         }
  493.  
  494. found:
  495.         if (q == REGISTER)
  496.                 scan_optional_equals();
  497.         else scan_keyword("by");
  498.         arith_error = FALSE;
  499.         if (q < MULTIPLY)  {
  500.                 if (p < GLUE_VAL) {
  501.                         if (p == INT_VAL)
  502.                                 scan_int();
  503.                         else scan_normal_dimen();
  504.                         if (q == ADVANCE)
  505.                                 cur_val += eqtb[l].i;
  506.                 } else {
  507.                         scan_glue(p);
  508.                         if (q == ADVANCE) {
  509.                                 q = new_spec(cur_val);
  510.                                 r = equiv(l);
  511.                                 delete_glue_ref(cur_val);
  512.                                 width(q) += width(r);
  513.                                 if (stretch(q) == 0)
  514.                                         stretch_order(q) = NORMAL;
  515.                                 else if (stretch_order(q) == stretch_order(r))
  516.                                         stretch(q) += stretch(r);
  517.                                 else if (stretch_order(q) < stretch_order(r) &&
  518.                                                 stretch_order(r) != 0) {
  519.                                                 stretch(q) = stretch(r);
  520.                                                 stretch_order(q) = stretch_order(r);
  521.                                 }
  522.                                 if (shrink(q) == 0)
  523.                                         shrink_order(q) = NORMAL;
  524.                                 if (shrink_order(q) == shrink_order(r))
  525.                                         shrink(q) += shrink(r);
  526.                                 else if (shrink_order(q) < shrink_order(r) &&
  527.                                                 shrink_order(r) != 0) {
  528.                                                 shrink(q) = shrink(r); 
  529.                                                 shrink_order(q) = shrink_order(r);
  530.                                 }
  531.                                 cur_val = q;
  532.                         }
  533.                 }
  534.         } else {
  535.                 scan_int();
  536.                 if (p < GLUE_VAL) {
  537.                         if (q == MULTIPLY)
  538.                                 cur_val = nx_plus_y(eqtb[l].i, cur_val, 0L);
  539.                         else cur_val = x_over_n(eqtb[l].i, cur_val);
  540.                 } else {
  541.                         s = equiv(l);
  542.                         r = new_spec(s);
  543.                         if (q == MULTIPLY) {
  544.                                 width(r) = nx_plus_y(width(s), cur_val, 0L);
  545.                                 stretch(r) = nx_plus_y(stretch(s), cur_val, 0L);
  546.                                 shrink(r) = nx_plus_y(shrink(s), cur_val, 0L);
  547.                         } else {
  548.                                 width(r) = x_over_n(width(s), cur_val);
  549.                                 stretch(r) = x_over_n(stretch(s), cur_val);
  550.                                 shrink(r) = x_over_n(shrink(s), cur_val);
  551.                         }
  552.                         cur_val = r;
  553.                 }
  554.         }
  555.         if (arith_error) {
  556.                 print_err("Arithmetic overflow");
  557.                 help_overflow();
  558.                 error();
  559.                 return;
  560.         }
  561.         if (p < GLUE_VAL) {
  562.                 word_def(l, cur_val);
  563.         } else {
  564.                 trap_zero_glue();
  565.                 def(l, GLUE_REF, (ptr) cur_val);
  566.         }
  567. }
  568.  
  569. alter_aux()
  570. {
  571.         hword   c;
  572.  
  573.         if (cur_chr != abs(mode))
  574.                 report_illegal_case();
  575.         else {
  576.                 c = cur_chr;
  577.                 scan_optional_equals();
  578.                 if (c == VMODE)  {
  579.                         scan_normal_dimen();
  580.                         prev_depth = cur_val;
  581.                 } else {
  582.                         scan_int();
  583.                         if (cur_val <= 0 || cur_val > 32767) {
  584.                                 print_err("Bad space factor");
  585.                                 help_space_factor();
  586.                                 int_error(cur_val);
  587.                         } else space_factor = cur_val;
  588.                 }
  589.         }
  590. }
  591.  
  592. alter_prev_graf ()
  593. {
  594.         ptr             p;
  595.  
  596.         nest[nest_ptr] = cur_list;
  597.         p = nest_ptr;
  598.         while (abs(nest[p].mode_field) != VMODE)        
  599.                 decr(p);
  600.         scan_optional_equals();
  601.         scan_int();
  602.         if (cur_val < 0) {
  603.                 print_err("Bad ");
  604.                 print_esc("prevgraf");
  605.                 help_prevgraf();
  606.                 int_error(cur_val);
  607.         } else {
  608.                 nest[p].pg_field = cur_val;
  609.                 cur_list = nest[nest_ptr];
  610.         }
  611. }
  612.  
  613. alter_page_so_far ()
  614. {
  615.         hword   c;
  616.  
  617.         c = cur_chr;
  618.         scan_optional_equals(); 
  619.         scan_normal_dimen();
  620.         page_so_far[c] = cur_val;
  621. }
  622.  
  623. alter_integer ()
  624. {
  625.         hword   c;
  626.         
  627.         c = cur_chr;
  628.         scan_optional_equals();
  629.         scan_int();
  630.         if (c == 0)
  631.                 dead_cycles = cur_val;
  632.         else insert_penalties = cur_val;
  633. }
  634.  
  635. alter_box_dimen ()
  636. {
  637.         byte    b;
  638.         hword   c;
  639.         
  640.         c = cur_chr;
  641.         scan_eight_bit_int();
  642.         b = cur_val; 
  643.         scan_optional_equals();
  644.         scan_normal_dimen();
  645.         if (box(b) != NULL)
  646.                 mem[box(b) + c].sc = cur_val;
  647. }
  648.  
  649. new_font (a)
  650.         int             a;
  651. {
  652.         fnt             f;
  653.         scal    s;
  654.         str             t;
  655.         ptr             u;
  656.         int             old_setting;
  657.  
  658.         if (job_name == 0)
  659.                 open_log_file();
  660.         get_r_token();
  661.         u = cur_cs;
  662.         if (u >= HASH_BASE)
  663.                 t = text(u);
  664.         else if (u >= SINGLE_BASE) {
  665.                 if (u == NULL_CS)
  666.                         t = make_string_given("FONT");
  667.                 else t = u - SINGLE_BASE;
  668.         } else {
  669.                 old_setting = selector;
  670.                 selector = NEW_STRING;
  671.                 print("FONT");
  672.                 print_str(u - ACTIVE_BASE);
  673.                 selector = old_setting;
  674.                 str_room(1);
  675.                 t = make_string();
  676.         }
  677.         def(u, SET_FONT, NULL_FONT);
  678.         scan_optional_equals();
  679.         scan_file_name();
  680.         name_in_progress = TRUE;
  681.         if (scan_keyword("at")) {
  682.                 scan_normal_dimen();
  683.                 s = cur_val;
  684.                 if (s <= 0 || s >= 01000000000) {
  685.                         print_err("Improper `at' size (");
  686.                         print_scaled(s);
  687.                         print("pt), replaced by 10pt");
  688.                         help_font_at();
  689.                         error();
  690.                         s = 10 * UNITY;
  691.                 }
  692.         } else if (scan_keyword("scaled")) {
  693.                 scan_int();
  694.                 s = -cur_val;
  695.                 if (cur_val <= 0 || cur_val > 32768) {
  696.                         print_err("Illegal magnification has been changed to 1000");
  697.                         help_font_magnification();
  698.                         int_error(cur_val);
  699.                         s = -1000;
  700.                 }
  701.         } else s = -1000;
  702.         name_in_progress = FALSE;
  703.         for (f = FONT_BASE + 1; f <= font_ptr; f++) {
  704.                 if (str_eq_str(font_name[f], cur_name) &&
  705.                         str_eq_str(font_area[f], cur_area)) {
  706.                         if (s > 0) {
  707.                                 if (s == font_size[f])
  708.                                         goto common_end;
  709.                         } else if (font_size[f] == xn_over_d(font_dsize[f], -s, 1000L))
  710.                                 goto common_end;
  711.                 }
  712.         }
  713.         f = read_font_info(u, cur_name, cur_area, s);
  714.  
  715. common_end:
  716.         equiv(u) = f;
  717.         eqtb[FONT_ID_BASE + f] = eqtb[u];
  718.         font_id_text(f) = t;
  719. }
  720.  
  721. prepare_mag ()
  722. {
  723.         if (mag_set > 0 && mag != mag_set) {
  724.                 print_err("Incompatible magnification (");
  725.                 print_val(mag);
  726.                 print(");");
  727.                 print_nl(" the previous value will be retained");
  728.                 help_mag();
  729.                 int_error(mag_set);
  730.                 geq_word_define((ptr) INT_BASE + MAG_CODE, mag_set);
  731.         }
  732.         if (mag <= 0 || mag > 32768) {
  733.                 print_err("Illegal magnification has been changed to 1000");
  734.                 help_ill_mag();
  735.                 int_error(mag);
  736.                 geq_word_define((ptr) INT_BASE + MAG_CODE, 1000L);
  737.         }
  738.         mag_set = mag;
  739. }
  740.                 
  741. new_interaction ()
  742. {
  743.         print_ln();
  744.         interaction = cur_chr;
  745.         if (interaction == BATCH_MODE)
  746.                 selector = NO_PRINT;
  747.         else selector = TERM_ONLY;
  748.         if (job_name != 0)
  749.                 selector += 2;
  750. }
  751.  
  752. do_assignments ()
  753. {
  754.         loop {
  755.                 get_nbrx_token();
  756.                 if (cur_cmd <= MAX_NON_PREFIXED_COMMAND)
  757.                         break;
  758.                 prefixed_command();
  759.         }
  760. }
  761.  
  762. clopen_stream ()
  763. {       
  764.         int             c;
  765.         int             n;
  766.  
  767.         c = cur_chr;
  768.         scan_four_bit_int();
  769.         n = cur_val; 
  770.         if (read_open[n] != CLOSED) {
  771.                 a_close(read_file[n]);
  772.                 read_open[n] = CLOSED;
  773.         }
  774.         if (c != 0) {
  775.                 scan_optional_equals();
  776.                 scan_file_name();
  777.                 if (cur_ext == null_str)
  778.                         cur_ext = str_tex;
  779.                 pack_cur_name();
  780.                 if (read_file[n] = a_open_in())
  781.                         read_open[n] = JUST_OPENED;
  782.         }
  783. }
  784.  
  785. issue_message ()
  786. {
  787.         int             c;
  788.         str             s;
  789.         int             old_setting;
  790.  
  791.         c = cur_chr;
  792.         scan_toks(FALSE, TRUE);
  793.         old_setting = selector;
  794.         selector = NEW_STRING;
  795.         token_show(def_ref);
  796.         selector = old_setting;
  797.         flush_list(def_ref);
  798.         str_room(1);
  799.         s = make_string();
  800.         if (c == 0) {
  801.                 if (term_offset + length(s) > MAX_PRINT_LINE - 2)
  802.                         print_ln();
  803.                 else if (term_offset > 0 || file_offset > 0)
  804.                         print_char(' ');
  805.                 print_str(s);
  806.                 update_terminal();
  807.         } else {
  808.                 print_err("");
  809.                 print_str(s);
  810.                 if (err_help != NULL)
  811.                         use_err_help = TRUE;
  812.                 else if (long_help_seen)
  813.                         help_err_msg();
  814.                 else {
  815.                         if (interaction < ERROR_STOP_MODE)
  816.                                 long_help_seen = TRUE;
  817.                         help_poirot();
  818.                 }
  819.                 error();
  820.                 use_err_help = FALSE;
  821.         }
  822.         flush_string();
  823. }
  824.  
  825. give_err_help ()
  826. {
  827.         token_show(err_help);
  828. }
  829.  
  830. shift_case ()
  831. {
  832.         ptr             b;
  833.         byte    c;
  834.         ptr             p;
  835.         hword   t;
  836.  
  837.         b = cur_chr;
  838.         scan_toks(FALSE, FALSE);
  839.         for (p = token_link(def_ref); p != NULL; p = token_link(p)) {
  840.                 t = token(p);
  841.                 if (t < CS_TOKEN_FLAG + SINGLE_BASE) {
  842.                         if (t >= CS_TOKEN_FLAG)
  843.                                 t -= ACTIVE_BASE;
  844.                         c = t % 256;
  845.                         if (c < 128 && equiv(b + c) != 0)
  846.                                 t = 256 * (t / 256) + equiv(b + c);
  847.                         if (t >= CS_TOKEN_FLAG)
  848.                                 token(p) = t + ACTIVE_BASE;
  849.                         else token(p) = t;
  850.                 }
  851.         }
  852.         back_list(token_link(def_ref));
  853.         free_token(def_ref);
  854. }
  855.  
  856. show_whatever ()
  857. {
  858.         switch (cur_chr)
  859.         {
  860.         case SHOW_LISTS:
  861.                 begin_diagnostic();
  862.                 show_activities();
  863.                 break;
  864.  
  865.         case SHOW_BOX_CODE:
  866.                 scan_eight_bit_int();
  867.                 begin_diagnostic();
  868.                 print_nl("> \\box");
  869.                 print_val(cur_val);
  870.                 print_char('=');
  871.                 if (box(cur_val) == NULL)
  872.                         print("void");
  873.                 else show_box(box(cur_val));
  874.                 break;
  875.         
  876.         case SHOW_CODE:
  877.                 get_token();
  878.                 print_nl("> ");
  879.                 if (cur_cs != 0) {
  880.                         sprint_cs(cur_cs);
  881.                         print_char('=');
  882.                 }
  883.                 print_meaning();
  884.                 goto common_end;
  885.                 break;
  886.         
  887.         default:
  888.                 the_toks();
  889.                 print_nl("> ");
  890.                 token_show(temp_toks);
  891.                 flush_list(token_link(temp_toks));
  892.                 goto common_end;
  893.                 break;
  894.         }
  895.         end_diagnostic(TRUE);
  896.         print_err("OK");
  897.         if (selector == TERM_AND_LOG && tracing_online <= 0) {
  898.                 selector = TERM_ONLY;
  899.                 print(" (see the transcript file)");
  900.                 selector = TERM_AND_LOG;
  901.         }
  902.  
  903. common_end:
  904.         if (interaction < ERROR_STOP_MODE) {
  905.                 help0();
  906.                 decr(error_count);
  907.         } else if (tracing_online > 0)
  908.                 help_show_online();
  909.         else help_show();
  910.         error();
  911. }
  912.  
  913. /*
  914.  *      Help text
  915.  */
  916.  
  917. help_missing_cs ()
  918. {
  919.         help5("Please don't say `\\def cs{...}', say `\\def\\cs{...}'.",
  920.         "I've inserted an inaccessible control sequence so that your",
  921.         "definition will be completed without mixing me up too badly.",
  922.         "You can recover graciously from this error, if you're",
  923.         "careful; see exercise 27.2 in The TeXbook.");
  924. }
  925.  
  926. help_prefix ()
  927. {
  928.         help1("I'll pretend that you didn't say \\long or \\outer or \\global.");
  929. }
  930.  
  931. help_pref ()
  932. {
  933.         help1("I'll pretend that you didn't say \\long or \\outer here.");
  934. }
  935.  
  936. help_read_to ()
  937. {
  938.         help2("You should have said `\\read<number> to \\cs'.",
  939.         "I'm going to look for the \\cs now.");
  940. }
  941.  
  942. help_code ()
  943. {
  944.         help1("I'm going to use 0 instead of that illegal code value.");
  945. }
  946.  
  947. help_register ()
  948. {
  949.         help1("I'm forgetting what you said and not changing anything.");
  950. }
  951.  
  952. help_space_factor ()
  953. {
  954.         help1("I allow only values in the range 1..32767 here.");
  955. }
  956.  
  957. help_prevgraf ()
  958. {
  959.         help1("I allow only nonnegative values here.");
  960. }
  961.  
  962. help_overflow ()
  963. {
  964.         help2(" I can't carry out that multiplication or division,",
  965.         "since the result is out of range.");
  966. }
  967.  
  968. help_font_at ()
  969. {
  970.         help2("I can only handle fonts at positive sizes that are",
  971.         "less than 2048pt, so I've changed what you said to 10pt.");
  972. }
  973.  
  974. help_font_magnification ()
  975. {
  976.         help1("The magnification ratio must be between 1 and 32768.");
  977. }
  978.  
  979. help_mag()
  980. {
  981.         help2("I can handle only one magnification ratio per job. So I've",
  982.         "reverted to the magnification you used earlier on this run.");
  983. }
  984.  
  985. help_ill_mag ()
  986. {
  987.         help1("The magnification ratio must be between 1 and 32768.");
  988. }
  989.  
  990. help_err_msg ()
  991. {
  992.         help1("(That was another \\errmessage.)");
  993. }
  994.  
  995. help_poirot ()
  996. {
  997.         help4("This error message was generated by an \\errmessage",
  998.         "command, so I can't give any explicit help.",
  999.         "Pretend that you're Hercule Poirot: examine all clues,",/*DIFF*/
  1000.         "and deduce the truth by order and method.");
  1001. }
  1002.  
  1003. help_show_online ()
  1004. {
  1005.         help3("This isn't an error message; I'm just \\showing something.",
  1006.         "Type `I\\show...' to show more (e.g., \\show\\cs,",
  1007.         "\\showthe\\count10, \\showbox255, \\showlists).");
  1008. }
  1009.  
  1010. help_show ()
  1011. {
  1012.         help5("This isn't an error message; I'm just \\showing something.",
  1013.         "Type `I\\show...' to show more (e.g., \\show\\cs,",
  1014.         "\\showthe\\count10, \\showbox255, \\showlists).",
  1015.         "And type `I\\tracingonline=1\\show...' to show boxes and",
  1016.         "lists on your terminal as well as in the transcript file.");
  1017. }
  1018.